﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace My.Pattern.Factory
{
    public abstract class DataFactory
    {
        public abstract T Retrieve<T>(string key);
        public virtual void Archive(string key, object value)
        {
            ValidateBeforeArchiving(key, value);
        }
        public bool Contains(string key)
        {
            return Retrieve<object>(key) != null;
        }

        protected virtual void ValidateBeforeArchiving(string key, object value)
        {
            if (Contains(key))
            {
                throw new ArgumentException(string.Format("The object with key {0} has already existed!", key));
            }
        }
    }
}